﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
using ICalendar.CalendarProperties;

namespace ICalendar.CalendarProperties
{
    /// <summary>
    /// Defines the persistent, globally unique identifier for the calendar component.
    /// </summary>
    /// <remarks>
    /// The UID itself MUST be a globally unique identifier. The generator of the identifier MUST guarantee that the identifier is unique. There are several algorithms that can be used to accomplish this. The identifier is RECOMMENDED to be the identical syntax to the [RFC 822] addr-spec. A good method to assure uniqueness is to put the domain name or a domain literal IP address of the host on which the identifier was created on the right hand side of the "@", and on the left hand side, put a combination of the current calendar date and time of day (i.e., formatted in as a DATE-TIME value) along with some other currently unique (perhaps sequential) identifier available on the system (for example, a process id number). Using a date/time value on the left hand side and a domain name or domain literal on the right hand side makes it possible to guarantee uniqueness since no two hosts should be using the same domain name or IP address at the same time. Though other algorithms will work, it is RECOMMENDED that the right hand side contain some domain identifier (either of the host itself or otherwise) such that the generator of the message identifier can guarantee the uniqueness of the left hand side within the scope of that domain.
    /// 
    /// This is the method for correlating scheduling messages with the referenced "VEVENT", "VTODO", or "VJOURNAL" calendar component.
    /// 
    /// The full range of calendar components specified by a recurrence set is referenced by referring to just the "UID" property value corresponding to the calendar component. The "RECURRENCE-ID" property allows the reference to an individual instance within the recurrence set.
    /// 
    /// This property is an important method for group scheduling applications to match requests with later replies, modifications or deletion requests. Calendaring and scheduling applications MUST generate this property in "VEVENT", "VTODO" and "VJOURNAL" calendar components to assure interoperability with other group scheduling applications. This identifier is created by the calendar system that generates an iCalendar object.
    /// 
    /// Implementations MUST be able to receive and persist values of at least 255 characters for this property.
    /// </remarks>
    [Serializable]
    [XmlRoot("uid")]   
    public class UniqueIdentifier : CalendarPropertyBase<string>
    {

        public UniqueIdentifier(Guid value) : base(value.ToString())
        {
            
        }

        public UniqueIdentifier(string value) : base(value)
        {
            
        }

        public UniqueIdentifier() : base( Guid.NewGuid().ToString())
        {
        }

        protected override void SetValue(string value)
        {
            this.Value = value;
        }

        protected override string GetValue()
        {
            return this.Value;
        }

        protected override void SetParametersFromXParameters(XParameterCollection xparams)
        {

        }

        protected override XParameterCollection GetXParametersFromParameters()
        {
            return null;
        }

        protected override string[] GetXReservedParametersNames()
        {
            return null;
        }

        public static implicit operator UniqueIdentifier(Guid value)
        {
            return new UniqueIdentifier(value);
        }


    }
}